package com.pay.cloud;

import android.content.Context;
import android.content.Intent;
import android.speech.tts.TextToSpeech;

import com.pay.cloud.service.NetworkService;

public class Application extends android.app.Application {
    private static Application app;
    private static TextToSpeech speech;
    private Intent networkService;
    //private BroadcastReceiver reportReceiver;

    @Override
    public void onCreate() {
        super.onCreate();

        app = this;

        Context context = getApplicationContext();

        startService(networkService = new Intent(context, NetworkService.class));
        //reportReceiver = new ReportReceiver();
        //registerReceiver(reportReceiver, new IntentFilter(ReportReceiver.class.getName()));

    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        stopService(networkService);
        //unregisterReceiver(reportReceiver);
    }

    public static Context getContext() {
        return app.getApplicationContext();
    }

    public final static void speak(String text) {
        if (null != speech) {
            speech.shutdown();
        }
        speech = new TextToSpeech(getContext(), status -> speech.speak(text, TextToSpeech.QUEUE_FLUSH, null, null));
    }

    public final static void speak(int textId) {
        speak(getContext().getString(textId));
    }

}
